package com.xdja.netty.learn.arpackage;

import io.netty.bootstrap.Bootstrap;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.*;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;

import java.util.Scanner;

/**
 * description
 *
 * @author zk
 * @since 2018/7/25
 */
public class ZClient {
    public static void main(String[] args) throws InterruptedException {
        Bootstrap bootstrap = new Bootstrap();
        ChannelFuture channelFuture = bootstrap.group(new NioEventLoopGroup())
                .channel(NioSocketChannel.class)
                .handler(new ChannelInitializer<Channel>() {
                    @Override
                    protected void initChannel(Channel ch) throws Exception {
                        ch.pipeline().addLast(new ChannelInboundHandlerAdapter());
                    }
                }).connect("192.168.24.28", 8989).sync();

        ByteBuf byteBuf = Unpooled.buffer();
        byteBuf.writeInt(34);
        byteBuf.writeInt(89);
        channelFuture.channel().writeAndFlush(byteBuf).addListener(ChannelFutureListener.CLOSE);
        channelFuture.channel().closeFuture().sync();
    }
}
